﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DataAccess_Layer;
public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Label3.Text = ().ToString();//ok
        //lblVisitors.Text = Application["Visitors"].ToString();
        //this.RefreshShoppingCartInfo();
        if (!IsPostBack)
        {
            DropDownList3.DataSource = LinqDataSource1;
            DropDownList3.DataTextField = "Name";
            DropDownList3.DataValueField = "ID";
            DropDownList3.DataBind();
            DropDownList3.Items.Add("chọn loại sản phẩm");
            int index = DropDownList3.Items.Count - 1;
            DropDownList3.Items[index].Value = "-1";
            DropDownList3.SelectedIndex = index;
            
        }
        ShoppingCart sc = new ShoppingCart();
        try
        {

            DataTable dt = (DataTable)Session["ShoppingCart"];
            sc = (ShoppingCart)Session["ShoppingCart"];

            Label1.Text = dt.Rows.Count.ToString();
            if (sc.Total == 0)
            {
                Label2.Text = "0";
            }
            else
            {
                Label2.Text = String.Format("{0:0,0 }", sc.Total);
            }
    

        }
        catch
        {
            Label1.Text = "0";
            Label2.Text = "0";
        }

    }

    public void RefreshShoppingCartInfo()
    {
        ShoppingCart Cart = (ShoppingCart)Session["ShoppingCart"];
        ShoppingCart sc = new ShoppingCart();
        try
        {

            DataTable dt = (DataTable)Session["ShoppingCart"];
            sc = (ShoppingCart)Session["ShoppingCart"];

            Label1.Text = dt.Rows.Count.ToString();
            if (sc.Total == 0)
            {
                Label2.Text = "0";
            }
            else
            {
                Label2.Text = String.Format("{0:0,0 }", sc.Total);
            }

        }
        catch
        {
            Label1.Text = "0";
            Label2.Text = "0";
        }
        //lblAmount.Text = Cart.Total.ToString("#.#0");
        //lblItems.Text = Cart.Count.ToString();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //Response.Redirect("Products.aspx?txtSearch=" + txtSearch.Text);
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("ViewCart.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("AdvanceSearch.aspx?giatu=" + DropDownList2.SelectedValue + "&giaden=" + DropDownList6.SelectedValue + "&Speed=1");
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
            TextBox1.Text = "0";
        if (TextBox2.Text == "")
            TextBox2.Text = "0";
        Response.Redirect("AdvanceSearch.aspx?giatu=" + DropDownList4.SelectedValue + "&giaden=" + DropDownList5.SelectedValue + "&loaisp=" + DropDownList3.SelectedValue + "&tensp=" + TextBox1.Text + "&tentg=" + TextBox2.Text + "&Speed=0"); 
    }
}
